#include<iostream>
#include<vector>
using namespace std;

class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> vv;
        vv.resize(numRows);
        for (int i = 0; i < vv.size(); i++) {
            vv[i].resize(i + 1, 0);
            vv[i][0] = 1;
            vv[i][i] = 1;
        }
        for (int i = 0; i < vv.size(); i++) {
            for (int j = 0; j < vv[i].size(); j++) {
                if (vv[i][j] != 1) {
                    vv[i][j] = vv[i - 1][j - 1] + vv[i - 1][j];
                }
            }
        }
        return vv;
    }
};

class Solution2 {
public:
    int removeDuplicates(vector<int>& nums) {
        int rem[20015] = { 0 };
        vector<int>::iterator it = nums.begin();
        while (it != nums.end()) {
            if (rem[*it + 10000] == 0) {
                rem[*it + 10000] = 1;
                ++it;
            }
            else {
                it = nums.erase(it);
            }
        }
        return nums.size();
    }
};

class Solution3 {
public:
    int removeDuplicates(vector<int>& nums) {
        vector<int>::iterator its = nums.begin();
        vector<int>::iterator itf = nums.begin();
        while (itf != nums.end()) {
            if (*its != *itf) {
                ++its;
                *its = *itf;
                ++itf;
            }
            else ++itf;
        }
        nums.resize(its - nums.begin() + 1);
        return nums.size();
    }
};

class Solution4 {
public:
    vector<int> singleNumber(vector<int>& nums) {
        long long digit = 0;
        for (int e : nums) digit ^= e;
        digit = digit & (-digit);
        int type1 = 0, type2 = 0;
        for (int e : nums) {
            if (digit & e) {
                type1 ^= e;
            }
            else {
                type2 ^= e;
            }
        }
        return { type1,type2 };
    }
};


class Solution5 {
public:
    int singleNumber(vector<int>& nums) {
        int ans = 0;
        for (int i = 0; i < 32; i++) {
            int total = 0;
            for (int e : nums) {
                total += ((e >> i) & 1);
            }
            if (total % 3) {
                ans |= (1 << i);
            }
        }
        return ans;
    }
};